package com.xyc.petmallsystem.repository;

import com.xyc.petmallsystem.pojo.Personal;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Joel
 * @date 2021/12/5
 */
public interface PersonalRepository extends JpaRepository<Personal, Integer> {

    /*
    通过user_id 查找信息
     */
    @Query(value = "select * from personal where user_id  = :user_id", nativeQuery = true)
    Personal getInfo(Integer user_id);

    /*
    根据 user_id删除
     */
    @Modifying
    @Transactional
    @Query(value = "delete from personal where user_id = :user_id", nativeQuery = true)
    void delByUserId(Integer user_id);

    /*
    获取男性用户的数量
     */
    @Query(value = "select count(*) from personal where sex = 0 ", nativeQuery = true)
    Integer getUserGender0();

    /*
    获取女性用户的数量
     */
    @Query(value = "select count(*) from personal where sex = 1 ", nativeQuery = true)
    Integer getUserGender1();
}
